package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.Store;
import com.sxkf.template.entity.User;
import com.sxkf.template.entity.UserLike;
import com.sxkf.template.service.StoreService;
import com.sxkf.template.service.UserLikeService;
import com.sxkf.template.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 用户喜欢用户记录 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:58
 */
@Api(tags = "用户关注记录")
@RestController
@RequestMapping("/userLike")
public class UserLikeController {

    @Resource
    private UserLikeService userLikeService;

    @ApiOperation(value = "点赞/关注 用户")
    @PostMapping(value = "/user")
    public R<?> addUser(@RequestBody UserLike userLike){
        userLikeService.add(userLike);
        return R.success();
    }

    @ApiOperation(value = "是否 点赞/关注 用户")
    @GetMapping(value = "/isLikeUser")
    public R<Boolean> isLikeUser(@RequestParam String userId, @RequestParam String isLikeUser){
        Boolean res = userLikeService.isLikeUser(userId,isLikeUser);
        return R.success(res);
    }

    @ApiOperation(value = "取消点赞/关注 用户/店铺")
    @GetMapping(value = "/del")
    public R<?> del(@RequestParam String id){
        userLikeService.removeById(id);
        return R.success();
    }


    @ApiOperation(value = "点赞/关注 店铺")
    @PostMapping(value = "/store")
    public R<?> addStore(@RequestBody UserLike userLike){
        userLikeService.addStore(userLike);
        return R.success();
    }

    @ApiOperation(value = "是否 点赞/关注 店铺")
    @GetMapping(value = "/isLikeStore")
    public R<Boolean> isLikeStore(@RequestParam String userId, @RequestParam String storeId){
        Boolean res = userLikeService.isLikeStore(userId,storeId);
        return R.success(res);
    }


    @ApiOperation(value = "查询用户关注列表")
    @GetMapping(value = "/pageUser")
    public R<IPage<User>> pageUser(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId,@RequestParam(required = false) @ApiParam("0=综合，1=最新，2=最早") String sortType){
        IPage<User> result = userLikeService.pageUser(pageNo,pageSize,userId,sortType);
        return R.success(result);
    }

    @ApiOperation(value = "查询店铺关注列表")
    @GetMapping(value = "/pageStore")
    public R<IPage<Store>> pageStore(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId,@RequestParam(required = false) @ApiParam("0=综合，1=最新，2=最早") String sortType){
        IPage<Store> result = userLikeService.pageStore(pageNo, pageSize, userId, sortType);
        return R.success(result);
    }

    @ApiOperation(value = "查询用户粉丝列表")
    @GetMapping(value = "/pageFans")
    public R<IPage<User>> pageFans(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId,@RequestParam(required = false) @ApiParam("0=综合，1=最新，2=最早") String sortType){
        IPage<User> result = userLikeService.pageFans(pageNo, pageSize, userId, sortType);
        return R.success(result);
    }

    @ApiOperation(value = "查询好友列表")
    @GetMapping(value = "/pageFriend")
    public R<IPage<User>> pageFriend(@RequestParam Integer pageNo,@RequestParam Integer pageSize,@RequestParam String userId){
        IPage<User> result = userLikeService.pageFriend(pageNo, pageSize, userId);
        return R.success(result);
    }
}
